<template>
  <div class="daily-catd">
    <div @click="go_dailydetial(item)" class="card" v-for="(item, d_id) in CardItems" :key="d_id">
      <div class="card-word">
        <div class="card-word-left">
          <!-- 用户头像 -->
          <img class="user_touxiang" :src="item.d_img" alt="" />
          <!-- 用户名 -->
          <span class="user_name">{{ item.d_man_name }}</span>
        </div>

        <!-- 地点 -->
        <span class="user_city">{{ item.d_city }}</span>
      </div>
      <div class="card-img">
        <!-- 文章详情 -->
        <p>{{ item.d_detail }}</p>
        <!-- 文章配图 -->

        <img :src="item.d_img" alt="" />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  // props:[CardItems],
  data() {
    return {
      CardItems: [],
    };
  },
  methods: {
    // 获取三条最新日记数据
    getdairyData() {
      const url = 'dairy/selectThree';
      this.axios.post(url).then(res => {
        console.log(res);
        this.CardItems = res.data.data;
      });
    },

    // 跳转至日记详情
    go_dailydetial(item) {
      this.$router.push({
        name: 'deilydetial', //跳转至 deilydetial 路由
        query: {
          d_id: item.d_id,
        },
      });
      this.$route.query.name;
    },
  },
  mounted() {
    this.getdairyData();
  },
};
</script>
<style lang="scss" scoped>
.card {
  color: #36343c;
  background-color: white;
  width: 90%;
  height: 30rem;
  margin: 2rem auto;
  border-radius: 1rem;
  box-shadow: 0 0.4rem 0.8rem 0 rgba(0, 0, 0, 0.2), 0 0.6rem 2rem 0 rgba(0, 0, 0, 0.19);

  .card-word {
    clear: both;
    width: 90%;
    display: flex;
    justify-content: space-between;

    align-items: center;
    margin: auto;
    padding-top: 2rem;
    .card-word-left {
      width: 25rem;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .user_touxiang {
        display: block;
        width: 3rem;
        height: 3rem;
        //裁减掉多余部分,不拉伸 不失真
        object-fit: cover;
        border-radius: 50%;
        background-color: white;
      }

      .user_name {
        margin-left: 1.5rem;
        display: inline-block;
        font-weight: bold;
        font-size: 1.6rem;
      }
    }

    .user_city {
      color: #36343c;
    }
  }

  .card-img {
    width: 90%;
    height: 90%;
    margin: 0 auto;
    p {
      margin-top: 1rem;
      font-size: 1.5rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    img {
      margin-top: 1rem;
      width: 100%;
      height: 70%;
      border-radius: 1rem;
      //裁减掉多余部分,不拉伸 不失真
      object-fit: cover;
    }
  }
}
</style>
